package com.edu.design.prototype;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class Prototype implements Cloneable,Serializable{

	private static final long serialVersionUID = 1L;
	
	private String name;
	private Object object;
	
	//浅复制，基本数据类型重新创建，引用类型指向原来的
	public Object clone() throws CloneNotSupportedException{
		Prototype prototype = (Prototype) super.clone();
		return prototype;
	}
	
	//深复制
	public Object deepClone() throws IOException, ClassNotFoundException{
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		ObjectOutputStream oos = new ObjectOutputStream(bos);
		oos.writeObject(this);
		ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
		ObjectInputStream ois = new ObjectInputStream(bis);
		return ois.readObject();
	}
	
	public String getName() {
		return name;
	}

	public void setName(String pName) {
		name = pName;
	}

	public Object getObject() {
		return object;
	}

	public void setObject(Object pObject) {
		object = pObject;
	}


}
